RE = require './_re'
PG = require('fckoa/db/pg')

module.exports = (account)->
    account = account.trim().toLowerCase()

    if RE.MAIL.test(account)
        pos = 1
    else if RE.PHONE.test(account)
        pos = 2
    else
        pos = 0
    if pos
        table = ["mail", "phone"][pos-1]
        xid = await PG.select_val_id("auth."+table,account)
        if xid
            # switch pos
            #     when 1,2
            user_id = await PG.select_val_id("auth.user_"+table, xid)
                # when 3
                #     user_id = xid

        if user_id
            return [user_id, pos, xid]

    raise account:pos
